﻿/*-----------------------------------------------
// File: DictStoryBlo.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Dict.Dao;
using Dict.DataModel;

namespace Dict.Blo
{
    public class DictKillerBlo
    {
        public static Dictionary<int, TableKiller> cache=null;
        static int minKillNumber = 0;
        static int maxKillNumber = 0;
        public static TableKiller GetKillerData(int killNum)
        {
            if (cache == null)
            {
                cache = new Dictionary<int, TableKiller>();

                var minData = DictDataManager.Instance.tableKillerDao.CacheList[0];
                var maxData = DictDataManager.Instance.tableKillerDao.CacheList[DictDataManager.Instance.tableKillerDao.CacheList.Count - 1];

                minKillNumber = minData.killNum;
                maxKillNumber = maxData.killNum;
                
                for (int i= minKillNumber; i< maxKillNumber; i++)
                {
                    var killer = minData;
                    for (int j = 0; j < DictDataManager.Instance.tableKillerDao.CacheList.Count; j++)
                    {
                        var tempData = DictDataManager.Instance.tableKillerDao.CacheList[j];
                        if (tempData.killNum <= i)
                        {
                            killer= tempData;
                        }
                        else
                            break;
                    }

                    cache[i] = killer;
                }
            }

            killNum = Mathf.Clamp(killNum, minKillNumber, maxKillNumber-1);
            return cache[killNum];

            //TableKiller killerData = DictDataManager.Instance.tableKillerDao.CacheList[0];
            

            //for(int i=0;i<DictDataManager.Instance.tableKillerDao.CacheList.Count;i++)
            //{
            //    var tmpData = DictDataManager.Instance.tableKillerDao.CacheList[i];
            //    if(tmpData.killNum>killNum)
            //    {
            //        break;
            //    }
            //    else
            //    {
            //        killerData = tmpData;
            //    }
            //}
            //return killerData;
        }
    }
}